const http = require("http");
const router = require("./router.js");

const server = http.createServer();

server.on("request", (req, res) => {
  // 底层也是监听reqest事件
  console.log(
    "--------------------------Request event triggered-------------------------------"
  );
  console.log(`Request received: ${req.method} ${req.url}`);
});

// 可以添加多个事件监听器
server.on("request", (req, res) => {
  router(req, res);
});

server.on("error", (err) => {
  console.error("Server error:", err);
});

server.listen(3000, () => {
  console.log("Server is runing localhost:3000");
});
